local skel = fk.CreateSkill {
  name = "lb__shenjie",
}

Fk:loadTranslationTable {
  ["lb__shenjie"] = "神捷",
  --[":lb__shenjie"] = "每轮开始时，你可以更改自己的座次，若如此做，直到本轮结束，一名角色进入/脱离横置状态后，若你与其距离1以内，你可以获得其一张牌/摸一张牌。",
  --9.2
  --[":lb__shenjie"] = "每轮开始时，你可以将座次移动到两名角色之间，若如此做，直到本轮结束，一名角色进入/脱离横置状态后，若你与其距离1以内，你可以获得其一张牌/摸一张牌。",
  --10.5
  --[":lb__shenjie"] = "每轮开始时，你可以将座次移动到两名角色之间，若如此做，直到本轮结束，与你相邻的角色进入/脱离横置状态后，你可以获得其一张牌/摸一张牌。",
  --10.6
  [":lb__shenjie"] = "每轮开始时，你可以将座次移动到两名角色之间，若如此做，直到本轮结束，你或相邻角色进入/脱离横置状态后，你可以获得其一张牌/摸一张牌。",

  ["#lb__shenjie"] = "神捷：你可以更改自己的座次",
  ["#lb__shenjie_draw"] = "神捷：你可以摸一张牌",
  ["#lb__shenjie_prey"] = "神捷：你可以获得 %dest 一张牌",

  ["@@lb__shenjie-round"] = "神捷",

  ["$lb__shenjie1"] = "猫鼠游戏，开始。",
  ["$lb__shenjie2"] = "有好东西，跑起来！",
}

skel:addEffect(fk.RoundStart, { --也是传奇角色了，两个技能都要搞优先级
  priority = 6,-- 专属优先级
  can_trigger = function(self, event, target, player, data)
    return not (data.extra_data and table.contains(data.extra_data.lb__shenjie or {}, player.id))
  end,
  on_trigger = function (self, event, target, player, data)
    data.extra_data = data.extra_data or {}
    data.extra_data.lb__shenjie = data.extra_data.lb__shenjie or {}
    local room = player.room
    local ids = table.map(room.players, Util.IdMapper)
    for _, id in ipairs(ids) do
      local to = room:getPlayerById(id)
      if to:hasSkill(skel.name, true) and not table.contains(data.extra_data.lb__shenjie or {}, id) then
        table.insertIfNeed(data.extra_data.lb__shenjie, id)
        if to:hasSkill(skel.name) then
          self:doCost(event, target, to, data)
        end
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local seat = {}
    for i = 1 + 1, #room.players, 1 do -- 9.2 +1
      if i ~= player.seat then
        table.insert(seat, tostring(i))
      end
    end
    table.insert(seat, "Cancel")
    local n = room:askToChoice(player, {
      choices = seat,
      skill_name = skel.name,
      prompt = "#lb__shenjie",
    })
    event:setCostData(self, { n = n })
    return n ~= "Cancel"
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player, "@@lb__shenjie-round", 1)
    local seat = tonumber(event:getCostData(self).n)
    room:moveSeatTo(player, seat)
  end,
})

skel:addEffect(fk.ChainStateChanged, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name) and player:getMark("@@lb__shenjie-round") > 0
        and (player:getNextAlive() == target or player:getLastAlive() == target or target == player)
        --and player:distanceTo(target) <= 1
        and ((target.chained and not target:isNude()) or not target.chained)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local prompt = "#lb__shenjie_draw"
    if target.chained then
      if target:isNude() then return end
      prompt = "#lb__shenjie_prey::" .. target.id
    end
    return room:askToSkillInvoke(player, { skill_name = skel.name, prompt = prompt })
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if target.chained then
      local id = room:askToChooseCard(player, {
        target = target,
        flag = "he",
        skill_name = skel.name,
      })
      room:obtainCard(player, id, false, fk.ReasonPrey, player, skel.name)
    else
      player:drawCards(1, skel.name)
    end
  end,
})
--[[  --test
skel:addAcquireEffect(function (self, player, is_start)
  local room = player.room
  for _, to in ipairs(room.players) do
    room:handleAddLoseSkills(to, "lb__shenjie", nil, false, true)
  end
end)
--]]
return skel
